home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / misc / emu / APCNames12a.lha / APCNames / Sources.Amiga / Wildcard.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-09  |  1.5 KB  |  70 lines

  1. /* Wildcard.c */
  2.  
  3. #include "Wildcard.h"
  4. #include <string.h>
  5.  
  6. #include <clib/exec_protos.h>
  7. #include <clib/dos_protos.h>
  8. #include <libraries/dos.h>
  9. #include "exec/memory.h"
  10.  
  11. #define BUFFER_SIZE 8192
  12. #define ENTRY_LEN 40
  13. #define ANCHOR_SIZE sizeof(struct AnchorPath)+ENTRY_LEN
  14.  
  15. static BOOL patInstalled = FALSE;
  16. static char *bufPtr = NULL,*endPtr,*curPtr;
  17.  
  18. /*---------------------------------------------------------------------------*/
  19.  
  20. void SetPattern (char * pat)
  21. {
  22.  LONG rc,fnl;
  23.  BOOL ok = TRUE;
  24.  struct AnchorPath *ap;
  25.  char *fn;
  26.  
  27.  patInstalled = FALSE;
  28.  if(bufPtr=(char *)AllocMem(BUFFER_SIZE,MEMF_PUBLIC|MEMF_CLEAR)) {
  29.    endPtr = bufPtr;
  30.    patInstalled = TRUE;
  31.    if(ap=(struct AnchorPath *)AllocMem(ANCHOR_SIZE,MEMF_PUBLIC|MEMF_CLEAR)) {
  32.      ap->ap_Strlen = ENTRY_LEN;
  33.      ap->ap_BreakBits = 0;
  34.      if((rc = MatchFirst(pat,ap))!=ERROR_OBJECT_NOT_FOUND)
  35.        while(rc != ERROR_NO_MORE_ENTRIES && ok) {
  36.          fn = ap->ap_Info.fib_FileName;
  37.          fnl = strlen(fn);
  38.          if(endPtr+fnl >= bufPtr+BUFFER_SIZE) {
  39.            ok = FALSE;
  40.            continue;
  41.          }
  42.          strcpy(endPtr,fn);
  43.          endPtr += fnl+1;
  44.          rc = MatchNext(ap);
  45.        }
  46.      MatchEnd(ap);
  47.      FreeMem(ap,ANCHOR_SIZE);
  48.    }
  49.    curPtr = bufPtr;
  50.  }
  51. }
  52.  
  53. /*---------------------------------------------------------------------------*/
  54.  
  55. char *NextEntry (void)
  56. {
  57.  char *fn;
  58.  
  59.  if(!patInstalled)
  60.    return NULL;
  61.  if(curPtr == endPtr) {
  62.    FreeMem(bufPtr,BUFFER_SIZE);
  63.    patInstalled = FALSE;
  64.    return NULL;
  65.  }
  66.  fn = curPtr;
  67.  curPtr += strlen(curPtr)+1;
  68.  return fn;
  69. }
  70.